
///////////////////////////////////////////////////////////////////////////////
// defines for various items.
///////////////////////////////////////////////////////////////////////////////

//Pins
#define LEDR	PB4		// Pin 16, OC1B, PWM signal for RED
#define LEDG	PB3		// Pin 15, OC1A, PWM signal for GREEN
#define LEDB	PB2		// Pin 14, OC0A, PWM signal for BLUE
#define LEDI	PD5		// Pin 9,  OC0B, PWM signal for INTENSITY

#define DDRLEDR	DDB4		// Pin 16, OC1B, PWM signal for RED
#define DDRLEDG	DDB3		// Pin 15, OC1A, PWM signal for GREEN
#define DDRLEDB	DDB2		// Pin 14, OC0A, PWM signal for BLUE
#define DDRLEDI	DDD5		// Pin 9,  OC0B, PWM signal for INTENSITY

#define VALR    OCR1BL		// compare register for PWM RED
#define VALG    OCR1AL		// compare register for PWM GREEN
#define VALB    OCR0A		// compare register for PWM BLUE
#define VALI    OCR0B		// compare register for PWM INTENSITY

///////////////////////////////////////////////////////////////////////////////
// macros
///////////////////////////////////////////////////////////////////////////////

#define nop() asm("nop")

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#define HIGH 0x1
#define LOW  0x0

#define TRUE 0x1
#define FALSE 0x0

#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105

// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif

#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))

#define lowByte(w) ((uint8_t) ((w) & 0xff))
#define highByte(w) ((uint8_t) ((w) >> 8))

#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
#define bit(b) (1UL << (b))

typedef void (*voidFuncPtr)(void);
typedef unsigned int word;
typedef uint8_t boolean;
typedef uint8_t byte;
